import { Component, PropsWithChildren } from 'react'
import { View, Image } from '@tarojs/components'
import Taro, { getCurrentInstance } from '@/newTaro';

import { navigateTo } from '@/utilsFun/vxNative';
import './index.scss'

export default class Organization extends Component<PropsWithChildren> {
  constructor(props) {
    super(props);

    this.state = {
      contents: [
        {
          name: '小区党组织分布图',
          nav: '/pages/map/index',
          params: { title: '小区党组织分布图', mapType: 1 },
          icon: require('@/assets/distribute.png')
        },
        {
          name: '有事专找小管家', nav: '/pages/map/index',
          params: { title: '有事专找小管家', mapType: 2 },
          icon: require('@/assets/contacts.png')
        },
        {
          name: '党群服务站分布图', nav: '/pages/map/index',
          params: { title: '党群服务站分布图', mapType: 3 },
          icon: require('@/assets/service.png')
        },
        {
          name: '党员学习专栏', nav: '/pages/news/index', icon: require('@/assets/study.png'),
          params: {title: '党员学习专栏', articleType: 1 },
        },
        {
          name: '党组织活动公示', nav: '/pages/news/index',
          params: {title: '党组织活动公示', articleType: 2 },
          icon: require('@/assets/publicity.png')
        },
      ],
    };
  }
  componentWillMount() {
    const title = this.$instance.router.params.title;
    if (title) {
      Taro.setNavigationBarTitle({
        title: decodeURIComponent(title)
      });
    }
   }

  componentDidMount() { }

  componentWillUnmount() { }

  componentDidShow() { }

  componentDidHide() { }

	$instance = getCurrentInstance();

  handleNv(e) {
    const dataset = e.currentTarget.dataset;

    if (dataset?.nav) navigateTo(dataset.nav, dataset?.params)
  }

  render() {
    const { contents } = this.state;
    return (
      <View className='index'>

        <View className='home_bottom_text_wrap'>
          {contents.map((item, index) => (
            <View
              className='text_item'
              key={index}
              data-nav={item.nav}
              data-params={item.params}
              onClick={this.handleNv}
            >
              {item.icon ? <Image src={item.icon} ></Image> : null}
              {item?.name || ''}
            </View>
          ))}
        </View>
      </View>
    )
  }
}
